<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">


<p:dialog id="dialogCadastro" modal="true" width="50%" position="top"
	appendTo="@(body)" closable="false" resizable="true" draggable="true"
	widgetVar="dialogCadastroInternacao" header="Internação/Cirurgia">
	<p:ajax event="close" listener="#{internacaoMB.close}"
		update="frmDialogInternacao" />
	<h:form id="frmDialogInternacao">

		<h:panelGrid columns="1">
			<h:panelGrid columns="2">

				<p:outputLabel value="Codigo:"></p:outputLabel>
				<p:inputText value="#{internacaoMB.internacaoSelecionado.codigo}"
					disabled="true"></p:inputText>

				<p:outputLabel value="Usuario:"></p:outputLabel>
				<p:inputText
					value="#{internacaoMB.internacaoSelecionado.usuario.nome}"
					disabled="true"></p:inputText>
			</h:panelGrid>
			<h:panelGrid columns="4">

				<p:outputLabel value="Data de Entrada:" for="entrada"></p:outputLabel>
				<p:inputMask id="entrada"
					value="#{internacaoMB.internacaoSelecionado.entrada}" size="10"
					disabled="#{not internacaoMB.incluindo}" required="true"
					requiredMessage="Entrada é obrigatória!" maxlength="10"
					mask="99/99/9999">
					<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
				</p:inputMask>

				<p:outputLabel value="Data de Saída:" for="saida"></p:outputLabel>
				<p:inputMask id="saida"
					value="#{internacaoMB.internacaoSelecionado.saida}" size="10"
					disabled="#{internacaoMB.consultando}"
					requiredMessage="Saida é obrigatória!" maxlength="10"
					mask="99/99/9999">
					<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
					<p:ajax event="blur" update="dias,total"></p:ajax>
				</p:inputMask>
			</h:panelGrid>
			<h:panelGrid columns="2" rendered="#{internacaoMB.incluindo}">

				<p:outputLabel value="Cliente:" for="selectanimal"></p:outputLabel>
				<p:selectOneMenu
					value="#{internacaoMB.internacaoSelecionado.animal.cliente}"
					required="true" id="selectcliente" filter="true"
					style="width:200px" disabled="#{not internacaoMB.incluindo}"
					converter="clienteConverter">
					<f:selectItem itemLabel="" itemValue="#{null}"></f:selectItem>
					<f:selectItems value="#{internacaoMB.listaCliente}" var="cliente"
						itemLabel="#{cliente.dadosCadastro.nome}" itemValue="#{cliente}"></f:selectItems>
					<p:ajax event="change"
						listener="#{internacaoMB.preencheListaAnimal}" update="pnlanimal"></p:ajax>
				</p:selectOneMenu>
			</h:panelGrid>
			<h:panelGrid columns="1">
				<p:outputPanel id="pnlanimal">
					<h:panelGrid columns="2">
						<p:outputLabel value="Animal:" for="selectanimal"></p:outputLabel>
						<p:selectOneMenu
							value="#{internacaoMB.internacaoSelecionado.animal}"
							rendered="#{internacaoMB.incluindo}" required="true"
							id="selectanimal" filter="true" style="width:200px"
							disabled="#{not internacaoMB.incluindo}"
							converter="animalConverter">
							<f:selectItems value="#{internacaoMB.listaAnimal}" var="animal"
								itemLabel="#{animal.nomeAnimal}" itemValue="#{animal}"></f:selectItems>
						</p:selectOneMenu>

						<p:inputText
							value="#{internacaoMB.internacaoSelecionado.animal.nomeAnimal}"
							rendered="#{not internacaoMB.incluindo}" disabled="true"></p:inputText>
					</h:panelGrid>
				</p:outputPanel>
				<h:panelGrid columns="1">
					<h:panelGrid columns="2" rendered="#{internacaoMB.incluindo}">
						<p:outputLabel value="Tipo:" for="selecttiposerv"></p:outputLabel>
						<p:selectOneMenu style="width:200px"
							value="#{internacaoMB.internacaoSelecionado.servico.tipoServico}"
							required="true" id="selecttiposerv" filter="true"
							disabled="#{internacaoMB.consultando}">
							<f:selectItem itemLabel="" itemValue="#{null}"></f:selectItem>
							<f:selectItems value="#{internacaoMB.listaTipoServico}"
								var="tipo" itemLabel="#{tipo.descricao}" itemValue="#{tipo}"></f:selectItems>
							<p:ajax event="change" listener="#{internacaoMB.preencheServico}"
								update="outpnlservico"></p:ajax>
						</p:selectOneMenu>
					</h:panelGrid>
					<p:outputPanel id="outpnlservico">
						<h:panelGrid columns="2">
							<p:outputLabel value="Serviço:"></p:outputLabel>
							<p:selectOneMenu style="width:200px"
								value="#{internacaoMB.internacaoSelecionado.servico}"
								required="true" id="selectserv" filter="true"
								rendered="#{internacaoMB.incluindo}" converter="servicoConverter">
								<f:selectItem itemLabel="" itemValue="#{null}"></f:selectItem>
								<f:selectItems value="#{internacaoMB.listaServico}"
									var="servico" itemLabel="#{servico.descServico}"
									itemValue="#{servico}"></f:selectItems>
							</p:selectOneMenu>
							<p:inputText rendered="#{not internacaoMB.incluindo}"
								value="#{internacaoMB.internacaoSelecionado.servico.descServico}"
								disabled="true"></p:inputText>
						</h:panelGrid>
					</p:outputPanel>

					<h:panelGrid columns="2">
						<p:outputLabel value="Descrição:" for="iptdescricao"></p:outputLabel>

						<p:inputTextarea id="iptdescricao" onfocus="iptdescricao"
							value="#{internacaoMB.internacaoSelecionado.descricao}"
							disabled="#{internacaoMB.consultando}" required="true"
							style="width:250px" requiredMessage="Descricao é obrigatório!"
							maxlength="100"></p:inputTextarea>
					</h:panelGrid>
				</h:panelGrid>
			</h:panelGrid>
			<h:panelGrid columns="4">
				<p:outputLabel value="Funcionário:" for="selectfuncionario"></p:outputLabel>
				<p:selectOneMenu
					value="#{internacaoMB.internacaoSelecionado.funcionario}"
					required="true" id="selectfuncionario" filter="true"
					disabled="#{internacaoMB.consultando}" style="width:200px"
					converter="funcionarioConverter">
					<f:selectItems value="#{internacaoMB.listaFuncionario}"
						var="funcionario" itemLabel="#{funcionario.dadosCadastro.nome}"
						itemValue="#{funcionario}"></f:selectItems>
				</p:selectOneMenu>

				<p:outputLabel value="Medico Responsável:"
					for="selectmedicoVeterinario"></p:outputLabel>
				<p:selectOneMenu
					value="#{internacaoMB.internacaoSelecionado.medicoResponsavel}"
					required="true" id="selectmedicoVeterinario" filter="true"
					disabled="#{not internacaoMB.incluindo}" style="width:200px"
					converter="funcionarioConverter">
					<f:selectItems value="#{internacaoMB.listaMedicoVeterinario}"
						var="medicoVeterinario"
						itemLabel="#{medicoVeterinario.dadosCadastro.nome}"
						itemValue="#{medicoVeterinario}"></f:selectItems>
				</p:selectOneMenu>

				<p:outputLabel value="Horário Visita:" for="horarioVisita"></p:outputLabel>
				<p:inputMask id="horarioVisita"
					placeholder="Horário de Visitação Preferencial"
					value="#{internacaoMB.internacaoSelecionado.horarioVisita}"
					required="false" disabled="#{internacaoMB.consultando}"
					mask="99:99" converter="horaConverter">
				</p:inputMask>
			</h:panelGrid>
			<h:panelGrid columns="4">
				<p:outputLabel value="Qtd. Dias:"></p:outputLabel>
				<p:inputText id="dias"
					value="#{internacaoMB.internacaoSelecionado.qtdDias}"
					disabled="true" size="10"></p:inputText>

				<p:outputLabel value="Valor Total R$:"></p:outputLabel>
				<p:inputText id="total"
					value="#{internacaoMB.internacaoSelecionado.valorTotal}"
					converter="doubleConverter" disabled="true" size="10"></p:inputText>

				<p:outputLabel value="Status:" for="selectstatus"></p:outputLabel>
				<p:selectOneMenu
					value="#{internacaoMB.internacaoSelecionado.status}"
					required="true" id="selectstatus" filter="true"
					disabled="#{internacaoMB.consultando or internacaoMB.incluindo}">
					<f:selectItems value="#{internacaoMB.listaStatus}" var="status"
						itemLabel="#{status.descricao}" itemValue="#{status}"></f:selectItems>
				</p:selectOneMenu>
			</h:panelGrid>


			<h:panelGrid columns="2" style="border:0px">
				<p:commandButton value="Confirma"
					actionListener="#{internacaoMB.salvar}"
					rendered="#{not internacaoMB.consultando}"
					update=":frmTab:tabela,:mensagem"
					oncomplete="validaDialog(args,'dialogCadastroInternacao','frmDialogInternacao:dialogCadastro')" />


				<p:commandButton value="Cancela"
					onclick="dialogCadastroInternacao.hide()" immediate="true" />

			</h:panelGrid>
		</h:panelGrid>
	</h:form>
</p:dialog>

</html>